/**
 * 
 */
package db.queryBuilders;

import models.Address;

/**
 * @author Teja
 * 
 */
public class UserAccountQueryBuilder {

	private static final String DB_NAME = "movietixdb";
	private static final String SINGLE_QUOTE = "'";
	private static final String NULL_STR = "NULL";

	public static String RegisterUsersTable(String username, String password) {

		String query = "insert into movietixdb.users ";
		query += "values (" + AddSingleQuotesToString(username) + 
				", sha1(md5(" + AddSingleQuotesToString(password) + ")));";

		return query;
	}

	public static String RegisterUserRoleTable(String username, String roleName) {

		String query = "insert into movietixdb.user_roles ";
		query += "values (" + AddSingleQuotesToString(username) + ", ";
		query += AddSingleQuotesToString(roleName) + ");";

		return query;
	}

	public static String RegisterUserProfileTable(models.UserInfo userInfo) {

		// insert into movietixdb.user_profile
		// values (null,'teja1@umbc.edu','cocky3', 'teja','naraparaju');
		
		String query = "insert into movietixdb.user_profile ";
		query += "values (" + NULL_STR + ", ";
		query += AddSingleQuotesToString(userInfo.getUsername()) + ", ";
		query += AddSingleQuotesToString(userInfo.getFirstName()) + ", ";
		query += AddSingleQuotesToString(userInfo.getEmailAddress()) + ", ";
		query += AddSingleQuotesToString(userInfo.getLastName()) + "); ";

		return query;
	}

	public static String AddSingleQuotesToString(String string) {
		return SINGLE_QUOTE + string + SINGLE_QUOTE;
	}

	public static String RegisterAddressTable(Address address) {

		// values (null, '10859 beech creek drive','Columbia','MD', '21044',
		// 'USA', LAST_INSERT_ID());

		String query = "insert into movietixdb.address ";
		query += "values (" + NULL_STR + ", ";
		query += AddSingleQuotesToString(address.getStreetName()) + ", ";
		query += AddSingleQuotesToString(address.getCity()) + ", ";
		query += AddSingleQuotesToString(address.getState()) + ", ";
		query += AddSingleQuotesToString(address.getZipcode()) + ", ";
		query += AddSingleQuotesToString(address.getCountry()) + " ); ";

		return query;
	}

	public static String DoesUserExistInDBQuery(String username) {
		String query = "select users.username ";
		query += "from movietixdb.users ";
		query += "where users.username=" + "'" + username + "'";

		return query;
	}
	
	public static String DoesEmailExistInDBQuery(String emailAddress) {
		
		//select user_profile.user_profile_email
		//from user_profile
		//where user_profile.user_profile_email = 'teja1@umbc.edu';
		
		String query = "select user_profile.user_profile_email ";
		query += "from user_profile ";
		query += "where user_profile.user_profile_email =" + "'" + emailAddress + "';";

		return query;
	}

}
